﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <title>客户管理</title>
    <link href="/CSS/bootstrap3.3.5/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="/JqueryPlug/dtGrid/jquery.dtGrid.css" rel="stylesheet">
    <link href="/CSS/Base/BaseClass.css?cssver=4" rel="stylesheet" type="text/css" />
    <link href="/CSS/font-awesome-4.3.0/css/font-awesome.min.css" rel="stylesheet">
    <script src="/Scripts/jquery-1.11.2.min.js"></script>
    <script src="/Scripts/avalon.js"></script>
    <script src="/Scripts/jquery-migrate-1.1.0.min.js"></script>
    <script src="/JqueryPlug/dtGrid/jquery.dtGrid.js"></script>
    <script src="/CSS/bootstrap3.3.5/js/bootstrap.js" type="text/javascript"></script>
    <script src="/Scripts/SZHLCommon.js?jsver=5"></script>
    <style type="text/css">
        html, body {
            overflow: hidden;
        }

        ul {
            list-style: none;
            padding-left: 30px;
            font-size: 16px;
        }

            ul li {
                margin-bottom: 5px;
            }

                ul li .spanli:hover {
                    background-color: bisque;
                    cursor: pointer;
                }

            ul .spanwz {
                margin-left: 2px;
                padding: 2px;
            }

            ul .fa {
                cursor: pointer;
                color: crimson;
            }

        .panel {
            border-radius: 0;
        }

        .treefile {
            width: 20px;
            height: 18px;
            color: #1B9AF7;
        }

        dl {
            margin-bottom: 10px;
        }
    </style>

    <script>
        var grid, dtoption;

        //获取主要菜单
        dtoption = {
            lang: 'zh-cn',
            check: false,
            ajaxLoad: false,
            exportFileName: '客户列表',
            columns: [
                { id: 'ID', title: '序号', type: 'string', columnClass: 'text-center', hide: true },
                {
                    id: 'KHName', title: '客户名称', type: 'string', columnClass: 'text-center'
                },
                { id: 'KHLeiBie', title: '客户类别', type: 'string', columnClass: 'text-center' },
                { id: 'KHDW', title: '单位名称', type: 'string', columnClass: 'text-center' },
                { id: 'KHPhone', title: '联系号码', type: 'string', columnClass: 'text-center' },
                { id: 'KHZhiWu', title: '客户职务', type: 'string', columnClass: 'text-center' },
                { id: 'KHXinBie', title: '性别', type: 'string', columnClass: 'text-center' },
                { id: 'CRDate', title: '创建时间', type: 'string', columnClass: 'text-center' },
                {
                    id: 'KHFXRS', title: '负责人', type: 'string', columnClass: 'text-center', fastQuery: true, fastQueryType: 'lk', resolution: function (value, record, column, grid, dataNo, columnNo) {
                        return ComFunJS.convertuser(record.KHFXRS);
                    }
                },
            {
                id: 'Option', title: '打印', type: 'string', columnClass: 'text-center', resolution: function (value, record, column, grid, dataNo, columnNo) {

                    var content = "<button class='btn btn-xs btn-default' onclick=\"model.ViewPrint(" + record.ID + ",event)\"><i class='fa fa-edit'></i> 打印快递单</button>";
                    content += "<button class='btn btn-xs btn-default' onclick=\"model.ViewDT(" + record.ID + ",event)\"><i class='fa fa-edit'></i> 客户联系记录</button>";
                    if (record.CRUser == model.username) {
                        content += '<button class="btn btn-xs btn-default" onclick="model.EditKHGL(\'' + record.ID + '\',event);"><i class="fa fa-edit"></i>  编辑</button>';
                        content += '<button class="btn btn-xs btn-danger" style="margin-left:10px;"  onclick="model.DelKHGL(\'' + record.ID + '\',' + dataNo + ',event)"><i class="fa fa-trash-o"></i>  删除</button>';
                    }
                    return content;
                }
            }],
            gridContainer: 'dtgrid',
            toolbarContainer: 'dtgridTool',
            pageSize: 10,
            pageSizeLimit: [10, 20, 50],
            tools: 'faseQuery',
            onGridComplete: function (grid) {
                var log = '<p>表格加载完成。表格编号：' + grid.option.id + '。</p>';
            }
        };
        var model = avalon.define({
            $id: "USUERKHRZLIST",
            menutype: "",//菜单类型(0:我的客户.-1:"当前部门客户")
            selmenu: function (val) {
                model.menutype = val;
                model.CommonData.clear();
                model.GetKHData()
                model.queryuser = "";
                if (model.menutype == "-1") {
                    $.getJSON('/API/SZHLAPI.ashx?Action=GETUSERTREE', { P1: "1", }, function (resultData) {//获取可以查看日报的人员列表
                        model.userlist = resultData.Result;
                    })
                }
            },//选中菜单事件
            queryuser:"",
            username: ComFunJS.getnowuser(),
            userlist: {},
            folderclick: function (item, dom) {
                $(".divuser").hide();
                $(dom).parent().find("div").eq(0).toggle();
            },
            fnqueryuser: function (item) {
                if (item) {
                    model.queryuser = item.UserName;
                    model.CommonData.clear();
                    model.GetKHData();
                }

            },
            KHType: "",
            KHContent: "",
            CommonData: [],
            KHTypeData: [],
            TotalCount: "",
            UserCount: "",
            CRUserCount: "",
            ViewDT: function (id) {
                parent.ComFunJS.winviewform("/View/APPBaseView/APP_KHGL_LXJL.html?FormCode=KHGL&ID=" + id, "客户联系记录", "1000", "");
            },
            KHGLADD: function () {
                parent.ComFunJS.winviewform("/View/APPBaseView/APP_ADD_WF.html?FormCode=KHGL", "添加数据", "1000", "");
            },
            GetKHType: function () {
                $.getJSON('/API/FTAPI.ashx?Action=GETCOLUMNLIST', { P1: 8 }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        model.KHTypeData = resultData.Result;
                    }
                })
            },
            GetKHData: function () {
                $.getJSON('/API/FTAPI.ashx?Action=GETUSERKHGLDATA', { P1: model.KHType, P2: model.KHContent, b: model.menutype,  QUSER:  "'" + model.queryuser + "'" }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        model.CommonData = resultData.Result;
                        if (dtoption.datas != undefined) {
                            dtoption.originalDatas = model.CommonData;

                        } else {
                            dtoption.datas = model.CommonData;
                            grid = $.fn.DtGrid.init(dtoption);
                        }
                        grid.load()
                    }
                })
            },
            ViewPrint: function (ID, event) {
                if (event) {
                    event.stopPropagation();
                }
                parent.ComFunJS.winold("/View/APPBaseView/KHGL_Print.html?ID=" + ID);
            },
            EditKHGL: function (Id, event) {
                if (event) {
                    event.stopPropagation();
                }
                parent.ComFunJS.winviewform("/View/APPBaseView/APP_ADD_WF.html?FormCode=KHGL&ID=" + Id, "添加数据", "1000", "");
            },
            DelKHGL: function (Id, rowNumber, event) {
                if (event) {
                    event.stopPropagation();
                }
                if (confirm("确定要删除么？")) {
                    $.post("/API/FTAPI.ashx", { Action: "DELKHGLBYID", P1: Id }, function (result) {
                        var jsonresult = $.parseJSON(result)
                        if ($.trim(jsonresult.ErrorMsg) != "") {
                            ComFunJS.winwarning(jsonresult.ErrorMsg);
                        } else {
                            model.CommonData.remove(model.CommonData[rowNumber]);
                            dtoption.originalDatas = model.CommonData;
                            grid.load()
                            parent.ComFunJS.winsuccess("删除成功");
                        }
                    })
                }
            }
        });
        avalon.ready(function () {
            model.GetKHType();
            model.GetKHData();
            $.getJSON('/API/FTAPI.ashx?Action=GETKHGLMENUCOUNT', function (resultData) {
                if (resultData.ErrorMsg == "") {
                    model.TotalCount = resultData.Result == "0" ? "" : resultData.Result;
                    model.UserCount = resultData.Result1 == "0" ? "" : resultData.Result1;
                    model.CRUserCount = resultData.Result2 == "0" ? "" : resultData.Result2;
                }
            })
        })

    </script>
</head>
<body ms-controller="USUERKHRZLIST">
    <script type="avalon" id="tmpl">
        <ul>
            <li ms-repeat-branch="branch.SubBranch"><span class="spanli" ms-click="folderclick(branch,this)"> <i class="iconfont icon-bumenshezhi" style="color:#1B9AF7;"></i><span class="spanwz">{{branch.BranchName}}</span></span><div ms-include="'tmpl'" style="display:none"></div></li>
            <li ms-repeat-user="branch.SubUsers" ms-click="fnqueryuser(user)" class="sel">
                <span class="spanli">
                    <i class=" treefile iconfont icon-ren"></i>
                    <span class="spanwz">{{user.UserRealName}}</span>
                </span>
            </li>
        </ul>
    </script>
    <div class="container-fluid maindiv" style="margin-top: 20px" id="dvContent">
        <div style="width:140px;position:absolute">
            <ul class="list-group text-center  leftmenu ">
                <li class="list-group-item" ms-class-1="sel:menutype==''" ms-click="selmenu('')">
                    <div>
                        <i class="iconfont hvr-grow">&#xe614;</i>{{UserCount}}
                    </div>
                    <div>我的客户</div>
                </li>
                <li class="list-group-item " ms-class-1="sel:menutype=='-1'" style="border-top:0;margin-top:2px" ms-click="selmenu('-1')">
                    <div>
                        <i class="iconfont icon-bumen hvr-grow "></i>{{TotalCount}}
                    </div>
                    <div>部门客户</div>
                </li>
            </ul>
            <div class="panel panel-default" ms-if="menutype=='-1'" style="margin-left:2px">
                <div class=" panel-body" style="padding:5px 0 5px 0">
                    <ul style="padding-left: 10px;margin-top:10px;">
                        <li ms-repeat-branch="userlist.SubBranch">
                            <span class="spanli" ms-click="folderclick(branch,this)"><i class="iconfont icon-bumenshezhi" style="color:#1B9AF7;"></i><span class="spanwz">{{branch.BranchName}}</span></span>
                            <div ms-include="'tmpl'" class="divuser" style="display: none"></div>
                        </li>
                        <li ms-repeat-user="userlist.SubUsers" ms-click="fnqueryuser(user)">
                            <span class="spanli">
                                <i class=" treefile iconfont icon-ren"></i>
                                <span class="spanwz">{{user.UserRealName}}</span>
                            </span>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="row contentdv" style="margin-left:141px">
            <div class="col-xs-12">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-xs-9">
                                <div class="input-group">
                                    <div class="input-group-addon">查询条件</div>
                                    <select class="form-control" ms-duplex="KHType" style="width:30%" ms-change="GetKHData()">
                                        <option value="">全部客户类别</option>
                                        <option ms-attr-val="item.TypeNO" ms-repeat-item="KHTypeData">{{item.TypeNO}}</option>
                                    </select>
                                    <input id="tbSearch" class="form-control" style="width:70%" type="text" ms-duplex="KHContent" placeholder="输入客户姓名,单位名称,联系号码查询" />
                                    <span class="input-group-btn">
                                        <button class="btn btn-info" ms-click="GetKHData()">查询</button>
                                    </span>
                                </div>
                            </div>
                            <div class="col-xs-3 text-right">
                                <a href="#" id="btADD" ms-click="KHGLADD()" class="button  button-primary">添加客户</a>
                            </div>
                        </div>
                    </div>
                </div>
                <div id="dtgrid" style="margin-top:20px"></div>
                <div id="dtgridTool" class="dt-grid-toolbar-container"></div>
            </div>
        </div>
    </div>
</body>
</html>
